<template>
  <el-dialog
  :title="this.dataForm.pCode === 500000 ? '考试积分设置' : '答题积分设置'"
  :visible.sync="visible">
    <el-form :model="dataForm" :inline="true" label-width="80px">
      <el-row>
        <el-form-item prop="enable" label="是否开启">
          <el-switch
            v-model="dataForm.enable"
            active-color="#13ce66"
            :inactive-value = 0
            :active-value = 1
            inactive-color="#ff4949">
          </el-switch>
        </el-form-item>
      </el-row>
      <el-row v-if="dataForm.enable === 1">
        <el-col>
          <el-form-item label="是否重复" prop="isRepeat">
            <el-tooltip class="item" effect="dark" content="含义：能否重复得分" placement="top-start">
                <el-radio-group v-model="dataForm.isRepeat">
                  <el-radio :label="0">否</el-radio>
                  <el-radio :label="1">是</el-radio>
                </el-radio-group>
            </el-tooltip>
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="得分类型">
            <el-radio-group  v-model="dataForm.gradeType">
              <el-radio-button :label="0">每次得分</el-radio-button>
<!--              <el-radio-button :label="1">每天得分</el-radio-button>-->
<!--              <el-radio-button :label="2">每周得分</el-radio-button>-->
<!--              <el-radio-button :label="3">每月得分</el-radio-button>-->
            </el-radio-group>
            <span style="font-size: 12px">(注：考一次得一次分。)</span>
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item  prop="quesSpacing">
            <span style="margin-left: 12px">每答对<el-input-number controls-position="right"  :min="1"  v-model="dataForm.quesSpacing "/>题,奖励<el-input-number controls-position="right" :precision="1" :step="0.1" :min="0" v-model="dataForm.grade"/>积分</span>
          </el-form-item>
<!--          <el-form-item label="积分" prop="awardGrade">-->
<!--            -->
<!--          </el-form-item>-->
        </el-col>
        <el-form-item label="奖励积分" prop="awardGrade">
          <el-tooltip class="item" effect="dark" content="注：全部答对奖励积分" placement="top-start">
            <el-input-number controls-position="right" :precision="1" :step="0.1"  :min="0" v-model="dataForm.awardGrade"/>
          </el-tooltip>
        </el-form-item>
        <el-form-item v-if="dataForm.isRepeat === 1" label="积分上限" prop="topGrade">
          <el-input-number controls-position="right" :precision="1" :step="0.1" :min="0" v-model="dataForm.topGrade"/>
        </el-form-item>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="onsubmit()" :loading="loading">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      loading: false,
      dataForm: {
        enable: 0,
        grade: 1,
        awardGrade: 1,
        isRepeat: 1,
        quesSpacing: 1,
        markId: '',
        gradeType: 0,
        topGrade: 0,
        pCode: 500000,
        id: ''
      }
    }
  },
  methods: {
    init(id, pCode) {
      this.dataForm.pCode = pCode
      this.dataForm.markId = id
      this.visible = true
      this.getInfo()
    },
    // async getInfo() {
    //   let res = await this.$http.post(`/integral-admin/integral/examrule/getExamRule`)
    //   console.log(res)
    // }
    getInfo() {
      this.$http({
        url: this.$http.adornUrl('/integral-admin/integral/examrule/getExamRule'),
        method: 'post',
        data: {
          markId: this.dataForm.markId,
          pCode: this.dataForm.pCode
        }
      }).then(res => {
        if (res && res.code === 200) {
          this.dataForm = res.data
          this.dataForm.topGrade = res.data.topGrade === -1 ? 0 : res.data.topGrade
        } else {
        }
      })
    },
    arms() {
      return {
        markId: this.dataForm.markId,
        pCode: this.dataForm.pCode,
        enable: this.dataForm.enable,
        grade: this.dataForm.grade,
        isRepeat: this.dataForm.isRepeat,
        quesSpacing: this.dataForm.quesSpacing,
        topGrade: this.dataForm.topGrade,
        gradeType: this.dataForm.gradeType,
        awardGrade: this.dataForm.awardGrade
      }
    },
    async onsubmit() {
      let res = await this.$http({
        url: this.$http.adornUrl(`/integral-admin/integral/examrule/addOrUpdateExamRule`),
        method: 'post',
        data: this.arms()
      })
      console.log(this.arms)
      if (res.code === 200) {
        this.$notify.success({title: '成功', message: '保存成功！'})
        this.visible = false
      }
    }
  }
}
</script>

<style scoped>

</style>
